#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename Tp> inline void read(Tp &x){
    x=0;bool f=0;
    char c=getchar();
    while(!isdigit(c)&&c!='-')c=getchar();
    if(c=='-')f=1,c=getchar();
    while(isdigit(c))x=x*10+c-'0',c=getchar();
    if(f)x=-x;
}
template<typename Tp> inline void write(Tp x){
    if(x<0)putchar('-'),x=-x;
    if(x/10)write(x/10);
    putchar(x%10+'0');
}
const int N=100005;
ll n,m,A[N],c[N],T,X[4],K;
bool d[20][N];
int main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    read(n),read(m);
    srand(time(nullptr));
    for(int i=1;i<=n;i++)read(A[i]);
    for(int i=1;i<=m;i++)read(c[i]);
    K=ceil(log2(n));
    char cx;
    for(int i=1;i<=K;i++){
        for(int j=1;j<=(1<<(K-i));j++){
            cx=getchar();
            while(cx!='0'||cx!='1')cx=getchar();
            d[i][j]=(cx=='1');
        }
    }
    read(T);
    while(T--){
        for(int i=0;i<4;i++)read(X[i]);
        ll a[N];
        ll ans=0;
        for(int i=1;i<=n;i++)a[i]=A[i]^X[i%4];
        for(int i=1;i<=m;i++){
            int k=ceil(log2(c[i]));
            ans^=(i*rand());
        }
        write(ans);
        putchar('\n');
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}